<?php
require_once 'typeOfPictureDTO.php';
require_once 'dbHelper.php';

class typeOfPictureDAO extends dbHelper
{
    public function create($typeOfPiectureDTO)
	{
		$sql = "insert into typeOfPicture(name, discription)
                values('$typeOfPiectureDTO->name', 
                        '$typeOfPiectureDTO->discription')";
		parent::execQuery($sql);
		if(parent::getAffectedRows() > 0)
			return true;
		return false;
	}
    
    public function update($typeOfPiectureDTO)
	{
		$sql = "update typeOfPicture set  name = '$typeOfPiectureDTO->name',
                                  discription = '$typeOfPiectureDTO->discription'";
		parent::execQuery($sql);
		if(parent::getAffectedRows() > 0)
			return true;
		return false;
	}
    
    public function delete($typeId)
	{
		$sql = "delete from typeOfPicture where typeId = '$typeId'";
		parent::execQuery($sql);
		if(parent::getAffectedRows() > 0)
			return true;
		return false;
	}
    
    public function selectAll()
	{
		$listTypeOfPic = array();
		$sql = "select * from typeofpicture";
		$result = parent::execQuery($sql);
		if($result && parent::getNumRows($result) > 0)
		{
			while($row = parent::fetchArray($result))
			{
				$typeOfPicDTO = new typeOfPictureDTO($row[typeId], $row[name], $row[description]);
				$listTypeOfPic[count($listTypeOfPic)] = $typeOfPicDTO;
			}
		}
		return $listTypeOfPic;
	}
    
    public function selectById($typeId){
        /*$accDTO = new accountDTO($row[accId], $row[email], $row[password],
                                 $row[fullname], $row[address], $row[phone],
                                 $row[DOB], $row[sex], $row[joinDate], 
                                 $row[status], $row[avtUrl]);*/
        $sql = "select * from typeofpicture where typeId = '$typeId'";
        $typeDTO = parent::execQuery($sql);
        return mysql_fetch_array($typeDTO);
    }
}
?>